FILE(GLOB_RECURSE consensus_SOURCES "*.cpp")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")

INCLUDE(CheckIncludeFile)
CHECK_INCLUDE_FILE(byteswap.h HAVE_BYTESWAP_H)
CHECK_INCLUDE_FILE(endian.h HAVE_ENDIAN_H)

if(HAVE_ENDIAN_H AND HAVE_BYTESWAP_H)
    # endian.h byteswap.h are provided; =1 means no need to complie by myself
    ADD_DEFINITIONS(-DHAVE_ENDIAN_H -DHAVE_BYTESWAP_H
    -DHAVE_DECL_BSWAP_16=1 -DHAVE_DECL_BSWAP_32=1 -DHAVE_DECL_BSWAP_64=1
	-DHAVE_DECL_LE16TOH=1  -DHAVE_DECL_LE32TOH=1 -DHAVE_DECL_LE64TOH=1  
	-DHAVE_DECL_HTOLE16=1 -DHAVE_DECL_HTOLE32=1 -DHAVE_DECL_HTOLE64=1 
	-DHAVE_DECL_BE16TOH=1  -DHAVE_DECL_BE32TOH=1 -DHAVE_DECL_BE64TOH=1  
	-DHAVE_DECL_HTOBE16=1 -DHAVE_DECL_HTOBE32=1 -DHAVE_DECL_HTOBE64=1)
ELSE()
    # no endian.h , no byteswap.h
    ADD_DEFINITIONS(
    -DHAVE_DECL_BSWAP_16=0 -DHAVE_DECL_BSWAP_32=0 -DHAVE_DECL_BSWAP_64=0
	-DHAVE_DECL_LE16TOH=0  -DHAVE_DECL_LE32TOH=0 -DHAVE_DECL_LE64TOH=0  
	-DHAVE_DECL_HTOLE16=0 -DHAVE_DECL_HTOLE32=0 -DHAVE_DECL_HTOLE64=0 
	-DHAVE_DECL_BE16TOH=0  -DHAVE_DECL_BE32TOH=0 -DHAVE_DECL_BE64TOH=0  
	-DHAVE_DECL_HTOBE16=0 -DHAVE_DECL_HTOBE32=0 -DHAVE_DECL_HTOBE64=0)
ENDIF()

ADD_DEFINITIONS(-DBCK_STATIC=1)
ADD_LIBRARY(consensus_static STATIC ${consensus_SOURCES})
SET_TARGET_PROPERTIES(consensus_static PROPERTIES OUTPUT_NAME mvs_consensus)
TARGET_LINK_LIBRARIES(consensus_static ${Boost_LIBRARIES} )
TARGET_LINK_LIBRARIES(consensus_static ethash )
INSTALL(TARGETS consensus_static DESTINATION lib)

IF(ENABLE_SHARED_LIBS)
    ADD_DEFINITIONS(-DBCK_DLL=1)
  ADD_LIBRARY(consensus_shared SHARED ${consensus_SOURCES})
  SET_TARGET_PROPERTIES(consensus_shared PROPERTIES OUTPUT_NAME mvs_consensus)
  TARGET_LINK_LIBRARIES(consensus_shared ${Boost_LIBRARIES})
  TARGET_LINK_LIBRARIES(consensus_shared  ethash )
  INSTALL(TARGETS consensus_shared DESTINATION lib)
ENDIF()
